import { getuserApi } from "../../request/api"

export default {
  namespaced: true,
  state: {
    cartTotal: 10,
    userInfo: {
      nickName: "小李子",
      coin: 1000,
      headImg: require('../../assets/img/monad.png')
    }
  },
  mutations: {
    changuserInfo(state, payload) {
      state.cartTotal = payload.cartTotal;
      state.userInfo = payload.userInfo;
    },
    // 初始化数据
    inituseInfo(state) {
      state.cartTotal = 10;
      state.userInfo = {
        nickName: "小李子",
        coin: 1000,
        headImg: require('../../assets/img/monad.png')
      }
    }
  },
  actions: {
    async asyncchanguserInfo(context, payload) {
      // 1.发送请求+更新vue中的数据
      let user = await getuserApi();
      // console.log(user);
      if (user.code == 0) {
        context.commit('changuserInfo', user.data)
      }
    }

  }
}